﻿@using Pear.Web.Core
@inherits PearRazorPage<object>
@{ Layout = "~/Views/Shared/_UserBox.cshtml"; }
@{ ViewData["Title"] = "注册页";}
@section header
{
    <link rel="stylesheet" href="/admin/css/other/login.css" />
}
<div class="layui-form-item">
    <img class="logo" src="/admin/images/logo.png" />
    <div class="title">Pear Admin</div>
    <div class="desc">
        明 湖 区 最 具 影 响 力 的 设 计 规 范 之 一
    </div>
</div>
<div class="layui-form-item">
    <input placeholder="账 户 : admin " name="account" lay-verify="account" hover class="layui-input" />
</div>
<div class="layui-form-item">
    <input placeholder="密 码 : admin " name="password" lay-verify="password" hover class="layui-input" />
</div>
<div class="layui-form-item">
    <input placeholder="确认密码 : admin " name="password2" lay-verify="password" hover class="layui-input" />
</div>
<div class="layui-form-item">
    <button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
        注 册
    </button>
</div>

@section footer
{
    <script>
        layui.use(['form', 'jquery', 'button', 'popup', 'context'], function () {
            var form = layui.form;
            var button = layui.button;
            var popup = layui.popup;
            var $ = layui.jquery;
            var http = layui.http;

           

            form.verify({
                account: function (value, item) {
                    if (value.length < 4) return '请输入至少4位账户';
                },
                password: function (value) {
                    if (value.length < 4) return '请输入至少4位密码';
                }
            });

            form.on('submit(login)', function (data) {
                var btn = button.load({ elem: '.login' });
                $.ajax({
                    url:  '/api/auth/login',
                    data: JSON.stringify(data.field),
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    success: function (result) {
                        if (result.succeeded) {
                            btn.stop(function () {
                                popup.success("登录成功", function () {
                                    location.href = "index.html";
                                    // 将 token 存储 localStore
                                    context.put("token", "Bearer " + result.data.accessToken)
                                });
                            })
                        } else {
                            btn.stop(function () {
                                popup.failure("登录失败");
                            })
                        }
                    }
                })
                return false;
            });
        })
    </script>


}